#include <bits/stdc++.h>

#define in read()

using namespace std;

using ll = long long;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 10;

int val[N],s[N],ch[N][2],fa[N],lz[N],stk[N],top,n,m;

void pushup(int x) {s[x] = val[x] ^ s[ch[x][0]] ^ s[ch[x][1]];}
void pushdn(int x) {if(lz[x]) lz[ch[x][0]] ^= 1, lz[ch[x][1]] ^= 1, swap(ch[x][0],ch[x][1]),lz[x] = 0;}
bool isroot(int x) {return x != ch[fa[x]][0] && x != ch[fa[x]][1];}
void Rotate(int x) {
	int y = fa[x] , z = fa[y] , k = ch[y][1] == x;
	fa[x] = z; if(!isroot(y)) ch[z][ch[z][1] == y] = x;
	if(ch[x][k ^ 1]) fa[ch[x][k ^ 1]] = y; ch[y][k] = ch[x][k ^ 1];
	ch[x][k ^ 1] = y; fa[y] = x;
	pushup(y); pushup(x);
}
void Splay(int x) {
	stk[top = 1] = x; for(int t = x; !isroot(t) ; t = fa[t]) stk[++top] = fa[t]; while(top) pushdn(stk[top--]);
	while(!isroot(x)) {
		int y = fa[x] , z = fa[y];
		if(!isroot(y)) (ch[z][0] == y) ^ (ch[y][0] == x) ? Rotate(x) : Rotate(y);
		Rotate(x);
	}
}
void access(int x) { for(int y = 0; x ; y = x,x = fa[x]) Splay(x),ch[x][1] = y,pushup(x);}
void makeroot(int x) { access(x); Splay(x); lz[x] ^= 1;}
int findroot(int x) { access(x); Splay(x); pushdn(x); while(ch[x][0]) x = ch[x][0],pushdn(x); Splay(x); return x;}
void link(int x,int y) { makeroot(x); if(findroot(y) != x) fa[x] = y;}
void cut(int x,int y) { makeroot(x); if(findroot(y) == x && fa[y] == x && !ch[y][0]) fa[y] = ch[x][1] = 0,pushup(x);}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in; for(int i = 1;i <= n;i++) val[i] = s[i] = in;
	while(m--) {
		int op = in,x = in,y = in;
		if(op == 0) makeroot(x),access(y),Splay(y),printf("%d\n",s[y]);
		else if(op == 1) link(x,y);
		else if(op == 2) cut(x,y);
		else makeroot(x),val[x] = y,pushup(x);
	}
	return 0;
}
